----------------------------------Spell Variables--------------------------------------
SPELL.m_iSpellID = 60 -- Whatever value you want as long as it doesn't override any other spells' IDs.
SPELL.m_iRange = 240
SPELL.m_sName = "Whirlwind"
SPELL.m_sToolTip =	[[You spin in circles, causing 
					 50% weapon damage in all 
					 directions for 5 yards.]]
SPELL.m_sIcon = "devin/blackbetty/spells/lifebinder/bloodfunnel.png"
SPELL.m_iCoolDown = 2
SPELL.m_iManaCost = 50
SPELL.m_bRequiresTarget = false
SPELL.m_iSpellType = SPELLTYPE_MELEEDAMAGE
SPELL.m_bRecastWhileCasting = false

---------------------------------------------------------------------------------------

local range = 100
local weapondamage = 10

function SPELL:Cast( pl, target )
	print("Casted "..self.m_sName.."!")
	pl.InSpellAnimation = true
	if(pl:IsPlayer())then
		pl:DoAnimationEvent(ACT_DI_ALYX_ZOMBIE_MELEE)
	else
		pl:RestartGesture(ACT_DI_ALYX_ZOMBIE_MELEE)
	end
	local weapon = nil
	if(pl:IsPlayer())then
		weapon = pl:GetWeapon("weapon_all")
	else
		target = pl.Target
	end
	pl.DoingCast = true
	pl.CastWhileMoving = true
	pl:EmitSound("devin/blackbetty/player/male/swing_common"..math.random(1,3)..".wav", 100, 100)
	pl:EmitSound("devin/blackbetty/weapons/whirlwind/whirlwind.wav", 100, 100)
	local whirlRadius = ents.FindInSphere(pl:GetPos(), 240)
	ParticleEffectAttach( "whirlwind", PATTACH_POINT_FOLLOW, pl, pl:LookupAttachment("anim_attachment_RH"))
	pl.DoingCast = true
	pl.CastWhileMoving = true
	timer.Simple(0.05, function()
		for i, s in ipairs(whirlRadius)do
			if(s and s:EntIndex() != pl:EntIndex() and s:IsPlayer() or s:IsNPC() or s:GetClass() == "npc_rpgdm")then
				self:Effect(pl, s)
			end
		end
	end)
	timer.Simple(0.8, function()
		pl.InSpellAnimation = false
		pl:SetNWBool("Casting", false)
		pl:SetNWBool("Casted", false)
	end)
end
	
function SPELL:Effect(pl, target)
	if(pl:IsPlayer())then
		weapon = pl:GetWeapon("weapon_all")
	else
		target = pl.Target
	end
	
	local dmginfo = DamageInfo()
		dmginfo:SetDamage(math.Round(math.random(weapon.MinWeaponDamage*1, weapon.MaxWeaponDamage*1.5))) --50 damage
		dmginfo:SetDamageType( DMG_SLASH ) --Bullet damage
		dmginfo:SetAttacker( pl ) --First player found gets credit
		dmginfo:SetDamageForce( Vector( 0, 0, 1000 ) ) --Launch upwards
	target:EmitSound("devin/blackbetty/weapons/GougeTarget.wav", 160, 100)
	target:TakeDamageInfo( dmginfo )
	ParticleEffect( "pummel_hit", target:GetPos() + Vector(0, 0, 46) + (target:GetAngles():Forward()*6), Angle(0,0,0), pl )
	ParticleEffect( "player_blood", target:GetPos() + Vector(0, 0, 46) + (target:GetAngles():Forward()*6), Angle(0,0,0), pl )
	if SERVER then
		target:SetVelocity(((pl:GetPos()- Vector(0, 0, 40)) - target:GetPos())*-3)
	end	
end





